class EntryImage < ActiveRecord::Base
    include Aggregator::EntryImageModel
    
    def self.get_photos_for_user(user_id, options = {})        
        sql = "SELECT entry_images.* "
        sql << "FROM entry_images "
        sql << "INNER JOIN entries on entries.id = entry_images.entry_id "
        sql << "INNER JOIN feeds on feeds.id = entries.feed_id "
        sql << "INNER JOIN aggregation_feeds ON aggregation_feeds.feed_id = feeds.id "
        sql << "INNER JOIN aggregations ON aggregations.id = aggregation_feeds.aggregation_id "
        sql << "WHERE aggregations.user_id = ? "
        sql << "ORDER By entries.published_at DESC "
        add_limit!(sql, options)
        args = [sql, user_id]
        Entry.find_by_sql(args)
    end
    
    def self.get_read_photos_for_user(user_id, options = {})        
        sql = "SELECT entry_images.* "
        sql << "FROM entry_images "
        sql << "INNER JOIN entries on entries.id = entry_images.entry_id "
        sql << "INNER JOIN entries_users on entries_users.entry_id = entry_images.entry_id "
        sql << "WHERE entries_users.user_id = ? "
        sql << "ORDER By entries.published_at DESC "
        add_limit!(sql, options)
        args = [sql, user_id]
        Entry.find_by_sql(args)
    end
    
    def self.get_marked_photos_for_user(user_id, options = {})        
        sql = "SELECT entry_images.* "
        sql << "FROM entry_images "
        sql << "INNER JOIN entries on entries.id = entry_images.entry_id "
        sql << "INNER JOIN marked_entries on marked_entries.entry_id = entry_images.entry_id "
        sql << "WHERE marked_entries.user_id = ? "
        sql << "ORDER By entries.published_at DESC "
        add_limit!(sql, options)
        args = [sql, user_id]
        Entry.find_by_sql(args)
    end    
    
end
